<?php

namespace app\admin\controller;

use think\facade\Db;
use app\admin\model\Admin as AdminModel;
use app\admin\validate\Admin as AdminValidate;

class User extends Controller
{
    protected function initialize()
    {
        parent::initialize();
    }

    /**
     * 用户信息
     */
    public function info()
    {
        $info = Db::name('admin')
            ->where('id', $this->admin['id'])
            ->find();
        unset($info['password']);
        return success('操作成功', $info);
    }

    /**
     * 修改密码
     */
    public function updatePassword()
    {
        $data = input('post.');
        $validate = new AdminValidate;
        if (!$validate->scene('updatePassword')->check($data)) {
            return fail($validate->getError());
        }

        $model = new AdminModel;
        $data['admin_id'] = $this->admin['id'];
        return $model->updatePassword($data);
    }

    /**
     * 上传头像
     */
    public function uploadAvatar()
    {
        $model = new AdminModel;
        return $model->uploadAvatar($this->admin['id']);
    }
}
